---
layout: "default"
title: "Dictionary"
description: "Swift documentation for 'Dictionary': A collection whose elements are key-value pairs."
keywords: "Dictionary,struct,swift,documentation,!=,==,contains,distance,dropFirst,dropFirst,dropLast,dropLast,elementsEqual,enumerated,filter,first,flatMap,flatMap,forEach,formIndex,formIndex,formIndex,index,index,index,index,index,lexicographicallyPrecedes,makeIterator,map,max,min,popFirst,prefix,prefix,prefix,reduce,remove,removeAll,removeValue,removeValue,reversed,sorted,split,starts,suffix,suffix,updateValue,updateValue,count,customMirror,debugDescription,description,endIndex,first,isEmpty,keys,lazy,startIndex,underestimatedCount,values,Element,Index,Iterator,SubSequence"
root: "/v3.0"
---

<div class="intro-declaration"><code class="language-swift">struct Dictionary&lt;Key : Hashable, Value&gt;</code></div>

<div class="discussion comment">
    <p>A collection whose elements are key-value pairs.</p>

<p>A dictionary is a type of hash table, providing fast access to the entries
it contains. Each entry in the table is identified using its key, which is
a hashable type such as a string or number. You use that key to retrieve
the corresponding value, which can be any object. In other languages,
similar data types are known as hashes or associated arrays.</p>

<p>Create a new dictionary by using a dictionary literal. A dictionary literal
is a comma-separated list of key-value pairs, in which a colon separates
each key from its associated value, surrounded by square brackets. You can
assign a dictionary literal to a variable or constant or pass it to a
function that expects a dictionary.</p>

<p>Here&#39;s how you would create a dictionary of HTTP response codes and their
related messages:</p>

<pre><code class="language-swift">var responseMessages = [200: &quot;OK&quot;,
                        403: &quot;Access forbidden&quot;,
                        404: &quot;File not found&quot;,
                        500: &quot;Internal server error&quot;]</code></pre>

<p>The <code>responseMessages</code> variable is inferred to have type <code>[Int: String]</code>.
The <code>Key</code> type of the dictionary is <code>Int</code>, and the <code>Value</code> type of the
dictionary is <code>String</code>.</p>

<p>To create a dictionary with no key-value pairs, use an empty dictionary
literal (<code>[:]</code>).</p>

<pre><code class="language-swift">var emptyDict: [String: String] = [:]</code></pre>

<p>Any type that conforms to the <code>Hashable</code> protocol can be used as a
dictionary&#39;s <code>Key</code> type, including all of Swift&#39;s basic types. You can use
your own custom types as dictionary keys by making them conform to the
<code>Hashable</code> protocol.</p>

<h1>Getting and Setting Dictionary Values</h1>

<p>The most common way to access values in a dictionary is to use a key as a
subscript. Subscripting with a key takes the following form:</p>

<pre><code class="language-swift">print(responseMessages[200])
// Prints &quot;Optional(&quot;OK&quot;)&quot;</code></pre>

<p>Subscripting a dictionary with a key returns an optional value, because a
dictionary might not hold a value for the key that you use in the
subscript.</p>

<p>The next example uses key-based subscripting of the <code>responseMessages</code>
dictionary with two keys that exist in the dictionary and one that does
not.</p>

<pre><code class="language-swift">let httpResponseCodes = [200, 403, 301]
for code in httpResponseCodes {
    if let message = responseMessages[code] {
        print(&quot;Response \(code): \(message)&quot;)
    } else {
        print(&quot;Unknown response \(code)&quot;)
    }
}
// Prints &quot;Response 200: OK&quot;
// Prints &quot;Response 403: Access Forbidden&quot;
// Prints &quot;Unknown response 301&quot;</code></pre>

<p>You can also update, modify, or remove keys and values from a dictionary
using the key-based subscript. To add a new key-value pair, assign a value
to a key that isn&#39;t yet a part of the dictionary.</p>

<pre><code class="language-swift">responseMessages[301] = &quot;Moved permanently&quot;
print(responseMessages[301])
// Prints &quot;Optional(&quot;Moved permanently&quot;)&quot;</code></pre>

<p>Update an existing value by assigning a new value to a key that already
exists in the dictionary. If you assign <code>nil</code> to an existing key, the key
and its associated value are removed. The following example updates the
value for the <code>404</code> code to be simply &quot;Not found&quot; and removes the
key-value pair for the <code>500</code> code entirely.</p>

<pre><code class="language-swift">responseMessages[404] = &quot;Not found&quot;
responseMessages[500] = nil
print(responseMessages)
// Prints &quot;[301: &quot;Moved permanently&quot;, 200: &quot;OK&quot;, 403: &quot;Access forbidden&quot;, 404: &quot;Not found&quot;]&quot;</code></pre>

<p>In a mutable <code>Dictionary</code> instance, you can modify in place a value that
you&#39;ve accessed through a keyed subscript. The code sample below declares a
dictionary called <code>interestingNumbers</code> with string keys and values that
are integer arrays, then sorts each array in-place in descending order.</p>

<pre><code class="language-swift">var interestingNumbers = [&quot;primes&quot;: [2, 3, 5, 7, 11, 13, 15],
                          &quot;triangular&quot;: [1, 3, 6, 10, 15, 21, 28],
                          &quot;hexagonal&quot;: [1, 6, 15, 28, 45, 66, 91]]
for key in interestingNumbers.keys {
    interestingNumbers[key]?.sort(by: &gt;)
}

print(interestingNumbers[&quot;primes&quot;]!)
// Prints &quot;[15, 13, 11, 7, 5, 3, 2]&quot;</code></pre>

<h1>Iterating Over the Contents of a Dictionary</h1>

<p>Every dictionary is an unordered collection of key-value pairs. You can
iterate over a dictionary using a <code>for</code>-<code>in</code> loop, decomposing each
key-value pair into the elements of a tuple.</p>

<pre><code class="language-swift">let imagePaths = [&quot;star&quot;: &quot;/glyphs/star.png&quot;,
                  &quot;portrait&quot;: &quot;/images/content/portrait.jpg&quot;,
                  &quot;spacer&quot;: &quot;/images/shared/spacer.gif&quot;]

for (name, path) in imagePaths {
    print(&quot;The path to &#39;\(name)&#39; is &#39;\(path)&#39;.&quot;)
}
// Prints &quot;The path to &#39;star&#39; is &#39;/glyphs/star.png&#39;.&quot;
// Prints &quot;The path to &#39;portrait&#39; is &#39;/images/content/portrait.jpg&#39;.&quot;
// Prints &quot;The path to &#39;spacer&#39; is &#39;/images/shared/spacer.gif&#39;.&quot;</code></pre>

<p>The order of key-value pairs in a dictionary is stable between mutations
but is otherwise unpredictable. If you need an ordered collection of
key-value pairs and don&#39;t need the fast key lookup that <code>Dictionary</code>
provides, see the <code>DictionaryLiteral</code> type for an alternative.</p>

<p>You can search a dictionary&#39;s contents for a particular value using the
<code>contains(where:)</code> or <code>index(where:)</code> methods supplied by default
implementation. The following example checks to see if <code>imagePaths</code> contains
any paths in the <code>&quot;/glyphs&quot;</code> directory:</p>

<pre><code class="language-swift">let glyphIndex = imagePaths.index { $0.value.hasPrefix(&quot;/glyphs&quot;) }
if let index = glyphIndex {
    print(&quot;The &#39;\(imagesPaths[index].key)&#39; image is a glyph.&quot;)
} else {
    print(&quot;No glyphs found!&quot;)
}
// Prints &quot;The &#39;star&#39; image is a glyph.&quot;)</code></pre>

<p>Note that in this example, <code>imagePaths</code> is subscripted using a dictionary
index. Unlike the key-based subscript, the index-based subscript returns
the corresponding key-value pair as a non-optional tuple.</p>

<pre><code class="language-swift">print(imagePaths[glyphIndex!])
// Prints &quot;(&quot;star&quot;, &quot;/glyphs/star.png&quot;)&quot;</code></pre>

<p>A dictionary&#39;s indices stay valid across additions to the dictionary as
long as the dictionary has enough capacity to store the added values
without allocating more storage. When a dictionary outgrows its storage,
existing indices may be invalidated without any notification.</p>

<p>When you know how many new values you&#39;re adding to a dictionary, use the
<code>init(minimumCapacity:)</code> initializer to allocate the correct amount of
storage.</p>

<h1>Bridging Between Dictionary and NSDictionary</h1>

<p>You can bridge between <code>Dictionary</code> and <code>NSDictionary</code> using the <code>as</code>
operator. For bridging to be possible, the <code>Key</code> and <code>Value</code> types of a
dictionary must be classes, <code>@objc</code> protocols, or types that bridge to
Foundation types.</p>

<p>Bridging from <code>Dictionary</code> to <code>NSDictionary</code> always takes O(1) time and
space. When the dictionary&#39;s <code>Key</code> and <code>Value</code> types are neither classes
nor <code>@objc</code> protocols, any required bridging of elements occurs at the
first access of each element. For this reason, the first operation that
uses the contents of the dictionary may take O(<em>n</em>).</p>

<p>Bridging from <code>NSDictionary</code> to <code>Dictionary</code> first calls the <code>copy(with:)</code>
method (<code>**copyWithZone:**</code> in Objective-C) on the dictionary to get an
immutable copy and then performs additional Swift bookkeeping work that
takes O(1) time. For instances of <code>NSDictionary</code> that are already
immutable, <code>copy(with:)</code> usually returns the same dictionary in O(1) time;
otherwise, the copying performance is unspecified. The instances of
<code>NSDictionary</code> and <code>Dictionary</code> share storage using the same copy-on-write
optimization that is used when two instances of <code>Dictionary</code> share
storage.</p>

<p><strong>See Also:</strong> <code>Hashable</code></p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">Collection, CustomDebugStringConvertible, CustomReflectable, CustomStringConvertible, ExpressibleByDictionaryLiteral, Indexable, IndexableBase, Sequence</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">Element = (key: Key, value: Value)</code>
<div class="comment">
    <p>The element type of a dictionary: a tuple containing an individual
key-value pair.</p>
</div>
</div>
<div class="declaration">
<code class="language-swift">Index = DictionaryIndex&lt;Key, Value&gt;</code>
<div class="comment">
    <p>The index type of a dictionary.</p>
</div>
</div>
<div class="declaration">
<code class="language-swift">Iterator = DictionaryIterator&lt;Key, Value&gt;</code>
<div class="comment">
    <p><em>Type alias inferred.</em></p>
</div>
</div>
<div class="declaration">
<code class="language-swift">SubSequence = Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
<div class="comment">
    <p><em>Type alias inferred.</em></p>
</div>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init">
<a class="toggle-link" data-toggle="collapse" href="#comment-init">init()</a><div class="comment collapse" id="comment-init"><div class="p">
    <p>Creates an empty dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init()</code>

    </div></div>
</div>
<div class="declaration" id="init-dictionaryliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-dictionaryliteral_">init(<wbr>dictionaryLiteral:)</a><div class="comment collapse" id="comment-init-dictionaryliteral_"><div class="p">
    <p>Creates a dictionary initialized with a dictionary literal.</p>

<p>Do not call this initializer directly. It is called by the compiler to
handle dictionary literals. To use a dictionary literal as the initial
value of a dictionary, enclose a comma-separated list of key-value pairs
in square brackets.</p>

<p>For example, the code sample below creates a dictionary with string keys
and values.</p>

<pre><code class="language-swift">let countryCodes = [&quot;BR&quot;: &quot;Brazil&quot;, &quot;GH&quot;: &quot;Ghana&quot;, &quot;JP&quot;: &quot;Japan&quot;]
print(countryCodes)
// Prints &quot;[&quot;BR&quot;: &quot;Brazil&quot;, &quot;JP&quot;: &quot;Japan&quot;, &quot;GH&quot;: &quot;Ghana&quot;]&quot;</code></pre>

<p><strong><code>elements</code>:</strong>  The key-value pairs that will make up the new
  dictionary. Each key in <code>elements</code> must be unique.</p>

<p><strong>See Also:</strong> <code>ExpressibleByDictionaryLiteral</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(dictionaryLiteral elements: (Key, Value)...)</code>

    </div></div>
</div>
<div class="declaration" id="init-minimumcapacity_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-minimumcapacity_">init(<wbr>minimumCapacity:)</a><div class="comment collapse" id="comment-init-minimumcapacity_"><div class="p">
    <p>Creates a dictionary with at least the given number of elements worth of
storage.</p>

<p>Use this initializer to avoid intermediate reallocations when you know
how many key-value pairs you are adding to a dictionary. The actual
capacity of the created dictionary is the smallest power of 2 that
is greater than or equal to <code>minimumCapacity</code>.</p>

<p><strong><code>minimumCapacity</code>:</strong>  The minimum number of key-value pairs to
  allocate storage for in the new dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(minimumCapacity: Int)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-count_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-count_-int">var count: Int</a><div class="comment collapse" id="comment-var-count_-int"><div class="p">
    <p>The number of key-value pairs in the dictionary.</p>

<p><strong>Complexity:</strong> O(1).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var count: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-custommirror_-mirror">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-custommirror_-mirror">var customMirror: Mirror</a><div class="comment collapse" id="comment-var-custommirror_-mirror"><div class="p">
    <p>A mirror that reflects the dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var customMirror: Mirror { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-debugdescription_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-debugdescription_-string">var debugDescription: String</a><div class="comment collapse" id="comment-var-debugdescription_-string"><div class="p">
    <p>A string that represents the contents of the dictionary, suitable for
debugging.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var debugDescription: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-description_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-description_-string">var description: String</a><div class="comment collapse" id="comment-var-description_-string"><div class="p">
    <p>A string that represents the contents of the dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var description: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-endindex_-dictionaryindex-key-value">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-endindex_-dictionaryindex-key-value">var endIndex: DictionaryIndex&lt;Key, Value&gt;</a><div class="comment collapse" id="comment-var-endindex_-dictionaryindex-key-value"><div class="p">
    <p>The dictionary&#39;s &quot;past the end&quot; position---that is, the position one
greater than the last valid subscript argument.</p>

<p>If the collection is empty, <code>endIndex</code> is equal to <code>startIndex</code>.</p>

<p><strong>Complexity:</strong> Amortized O(1) if the dictionary does not wrap a bridged
  <code>NSDictionary</code>; otherwise, the performance is unspecified.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var endIndex: DictionaryIndex&lt;Key, Value&gt; { get }</code>

    </div></div>
</div>
<div class="declaration inherited" id="var-first_-self-iterator-element">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-first_-self-iterator-element">var first: (key: Key, value: Value)?</a><div class="comment collapse" id="comment-var-first_-self-iterator-element"><div class="p">
    <p>The first element of the collection.</p>

<p>If the collection is empty, the value of this property is <code>nil</code>.</p>

<pre><code class="language-swift">let numbers = [10, 20, 30, 40, 50]
if let firstNumber = numbers.first {
    print(firstNumber)
}
// Prints &quot;10&quot;</code></pre>

    <h4>Declaration</h4>    
    <code class="language-swift">var first: (key: Key, value: Value)? { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/Collection/"><code>Collection</code></a>
        </div></div>
</div>
<div class="declaration" id="var-isempty_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isempty_-bool">var isEmpty: Bool</a><div class="comment collapse" id="comment-var-isempty_-bool"><div class="p">
    <p>A Boolean value that indicates whether the dictionary is empty. (read
only)</p>

<p>Dictionaries are empty when created with an initializer or an empty
dictionary literal.</p>

<pre><code class="language-swift">var frequencies: [String: Int] = [:]
print(frequencies.isEmpty)
// Prints &quot;true&quot;</code></pre>

    <h4>Declaration</h4>    
    <code class="language-swift">var isEmpty: Bool { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/Dictionary/"><code>Dictionary</code></a>
        ,    <a href="../../protocol/Collection/"><code>Collection</code></a>
        </div></div>
</div>
<div class="declaration" id="var-keys_-lazymapcollection-key_-value-key">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-keys_-lazymapcollection-key_-value-key">var keys: LazyMapCollection&lt;[Key : Value], Key&gt;</a><div class="comment collapse" id="comment-var-keys_-lazymapcollection-key_-value-key"><div class="p">
    <p>A collection containing just the keys of the dictionary.</p>

<p>When iterated over, keys appear in this collection in the same order as they
occur in the dictionary&#39;s key-value pairs. Each key in the keys
collection has a unique value.</p>

<pre><code class="language-swift">let countryCodes = [&quot;BR&quot;: &quot;Brazil&quot;, &quot;GH&quot;: &quot;Ghana&quot;, &quot;JP&quot;: &quot;Japan&quot;]
for k in countryCodes.keys {
    print(k)
}
// Prints &quot;BR&quot;
// Prints &quot;JP&quot;
// Prints &quot;GH&quot;</code></pre>

    <h4>Declaration</h4>    
    <code class="language-swift">var keys: LazyMapCollection&lt;[Key : Value], Key&gt; { get }</code>

    </div></div>
</div>
<div class="declaration inherited" id="var-lazy_-lazycollection-self">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-lazy_-lazycollection-self">var lazy: LazyCollection&lt;Dictionary&lt;Key, Value&gt;&gt;</a><div class="comment collapse" id="comment-var-lazy_-lazycollection-self"><div class="p">
    <p>A view onto this collection that provides lazy implementations of
normally eager operations, such as <code>map</code> and <code>filter</code>.</p>

<p>Use the <code>lazy</code> property when chaining operations to prevent
intermediate operations from allocating storage, or when you only
need a part of the final collection to avoid unnecessary computation.</p>

<p><strong>See Also:</strong> <code>LazySequenceProtocol</code>, <code>LazyCollectionProtocol</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var lazy: LazyCollection&lt;Dictionary&lt;Key, Value&gt;&gt; { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/Collection/"><code>Collection</code></a>
        </div></div>
</div>
<div class="declaration" id="var-startindex_-dictionaryindex-key-value">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-startindex_-dictionaryindex-key-value">var startIndex: DictionaryIndex&lt;Key, Value&gt;</a><div class="comment collapse" id="comment-var-startindex_-dictionaryindex-key-value"><div class="p">
    <p>The position of the first element in a nonempty dictionary.</p>

<p>If the collection is empty, <code>startIndex</code> is equal to <code>endIndex</code>.</p>

<p><strong>Complexity:</strong> Amortized O(1) if the dictionary does not wrap a bridged
  <code>NSDictionary</code>. If the dictionary wraps a bridged <code>NSDictionary</code>, the
  performance is unspecified.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var startIndex: DictionaryIndex&lt;Key, Value&gt; { get }</code>

    </div></div>
</div>
<div class="declaration inherited" id="var-underestimatedcount_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-underestimatedcount_-int">var underestimatedCount: Int</a><div class="comment collapse" id="comment-var-underestimatedcount_-int"><div class="p">
    <p>A value less than or equal to the number of elements in the collection.</p>

<p><strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the length
  of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var underestimatedCount: Int { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/Collection/"><code>Collection</code></a>
        ,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>
        </div></div>
</div>
<div class="declaration" id="var-values_-lazymapcollection-key_-value-value">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-values_-lazymapcollection-key_-value-value">var values: LazyMapCollection&lt;[Key : Value], Value&gt;</a><div class="comment collapse" id="comment-var-values_-lazymapcollection-key_-value-value"><div class="p">
    <p>A collection containing just the values of the dictionary.</p>

<p>When iterated over, values appear in this collection in the same order as they
occur in the dictionary&#39;s key-value pairs.</p>

<pre><code class="language-swift">let countryCodes = [&quot;BR&quot;: &quot;Brazil&quot;, &quot;GH&quot;: &quot;Ghana&quot;, &quot;JP&quot;: &quot;Japan&quot;]
print(countryCodes)
// Prints &quot;[&quot;BR&quot;: &quot;Brazil&quot;, &quot;JP&quot;: &quot;Japan&quot;, &quot;GH&quot;: &quot;Ghana&quot;]&quot;
for v in countryCodes.values {
    print(v)
}
// Prints &quot;Brazil&quot;
// Prints &quot;Japan&quot;
// Prints &quot;Ghana&quot;</code></pre>

    <h4>Declaration</h4>    
    <code class="language-swift">var values: LazyMapCollection&lt;[Key : Value], Value&gt; { get }</code>

    </div></div>
</div>

<h3>Subscripts</h3>
<div class="declaration" id="subscript-subscript_-hashable">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-hashable">subscript(_: _Hashable)</a>
<div class="comment collapse" id="comment-subscript-subscript_-hashable"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(key: _Hashable) -&gt; Value?</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="subscript-subscript_-closedrange-self-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-closedrange-self-index">subscript(_: ClosedRange&lt;DictionaryIndex&lt;Key, Value&gt;&gt;)</a>
<div class="comment collapse" id="comment-subscript-subscript_-closedrange-self-index"><div class="p">
    <p>Accesses a contiguous subrange of the collection&#39;s elements.</p>

<p>The accessed slice uses the same indices for the same elements as the
original collection. Always use the slice&#39;s <code>startIndex</code> property
instead of assuming that its indices start at a particular value.</p>

<p>This example demonstrates getting a slice of an array of strings, finding
the index of one of the strings in the slice, and then using that index
in the original array.</p>

<pre><code class="language-swift">let streets = [&quot;Adams&quot;, &quot;Bryant&quot;, &quot;Channing&quot;, &quot;Douglas&quot;, &quot;Evarts&quot;]
let streetsSlice = streets[2 ..&lt; streets.endIndex]
print(streetsSlice)
// Prints &quot;[&quot;Channing&quot;, &quot;Douglas&quot;, &quot;Evarts&quot;]&quot;

let index = streetsSlice.index(of: &quot;Evarts&quot;)    // 4
print(streets[index!])
// Prints &quot;Evarts&quot;</code></pre>

<p><strong><code>bounds</code>:</strong>  A range of the collection&#39;s indices. The bounds of
  the range must be valid indices of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(bounds: ClosedRange&lt;DictionaryIndex&lt;Key, Value&gt;&gt;) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt; { get }</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration" id="subscript-subscript_-dictionaryindex-key-value">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-dictionaryindex-key-value">subscript(_: DictionaryIndex&lt;Key, Value&gt;)</a>
<div class="comment collapse" id="comment-subscript-subscript_-dictionaryindex-key-value"><div class="p">
    <p>Accesses the key-value pair at the specified position.</p>

<p>This subscript takes an index into the dictionary, instead of a key, and
returns the corresponding key-value pair as a tuple. When performing
collection-based operations that return an index into a dictionary, use
this subscript with the resulting value.</p>

<p>For example, to find the key for a particular value in a dictionary, use
the <code>index(where:)</code> method.</p>

<pre><code class="language-swift">let countryCodes = [&quot;BR&quot;: &quot;Brazil&quot;, &quot;GH&quot;: &quot;Ghana&quot;, &quot;JP&quot;: &quot;Japan&quot;]
if let index = countryCodes.index(where: { $0.value == &quot;Japan&quot; }) {
    print(countryCodes[index])
    print(&quot;Japan&#39;s country code is &#39;\(countryCodes[index].key)&#39;.&quot;)
} else {
    print(&quot;Didn&#39;t find &#39;Japan&#39; as a value in the dictionary.&quot;)
}
// Prints &quot;(&quot;JP&quot;, &quot;Japan&quot;)&quot;
// Prints &quot;Japan&#39;s country code is &#39;JP&#39;.&quot;</code></pre>

<p><strong><code>position</code>:</strong>  The position of the key-value pair to access.
  <code>position</code> must be a valid index of the dictionary and not equal to
  <code>endIndex</code>.
<strong>Returns:</strong> A two-element tuple with the key and value corresponding to
  <code>position</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(position: DictionaryIndex&lt;Key, Value&gt;) -&gt; (key: Key, value: Value) { get }</code>
    
    
</div></div>
</div>
<div class="declaration" id="subscript-subscript_-key">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-key">subscript(_: Key)</a>
<div class="comment collapse" id="comment-subscript-subscript_-key"><div class="p">
    <p>Accesses the value associated with the given key for reading and writing.</p>

<p>This <em>key-based</em> subscript returns the value for the given key if the key
is found in the dictionary, or <code>nil</code> if the key is not found.</p>

<p>The following example creates a new dictionary and prints the value of a
key found in the dictionary (<code>&quot;Coral&quot;</code>) and a key not found in the
dictionary (<code>&quot;Cerise&quot;</code>).</p>

<pre><code class="language-swift">var hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]
print(hues[&quot;Coral&quot;])
// Prints &quot;Optional(16)&quot;
print(hues[&quot;Cerise&quot;])
// Prints &quot;nil&quot;</code></pre>

<p>When you assign a value for a key and that key already exists, the
dictionary overwrites the existing value. If the dictionary doesn&#39;t
contain the key, the key and value are added as a new key-value pair.</p>

<p>Here, the value for the key <code>&quot;Coral&quot;</code> is updated from <code>16</code> to <code>18</code> and a
new key-value pair is added for the key <code>&quot;Cerise&quot;</code>.</p>

<pre><code class="language-swift">hues[&quot;Coral&quot;] = 18
print(hues[&quot;Coral&quot;])
// Prints &quot;Optional(18)&quot;

hues[&quot;Cerise&quot;] = 330
print(hues[&quot;Cerise&quot;])
// Prints &quot;Optional(330)&quot;</code></pre>

<p>If you assign <code>nil</code> as the value for the given key, the dictionary
removes that key and its associated value.</p>

<p>In the following example, the key-value pair for the key <code>&quot;Aquamarine&quot;</code>
is removed from the dictionary by assigning <code>nil</code> to the key-based
subscript.</p>

<pre><code class="language-swift">hues[&quot;Aquamarine&quot;] = nil
print(hues)
// Prints &quot;[&quot;Coral&quot;: 18, &quot;Heliotrope&quot;: 296, &quot;Cerise&quot;: 330]&quot;</code></pre>

<p><strong><code>key</code>:</strong>  The key to find in the dictionary.
<strong>Returns:</strong> The value associated with <code>key</code> if <code>key</code> is in the dictionary;
  otherwise, <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(key: Key) -&gt; Value?</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="subscript-subscript_-range-self-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-range-self-index">subscript(_: Range&lt;DictionaryIndex&lt;Key, Value&gt;&gt;)</a>
<div class="comment collapse" id="comment-subscript-subscript_-range-self-index"><div class="p">
    <p>Accesses a contiguous subrange of the collection&#39;s elements.</p>

<p>The accessed slice uses the same indices for the same elements as the
original collection uses. Always use the slice&#39;s <code>startIndex</code> property
instead of assuming that its indices start at a particular value.</p>

<p>This example demonstrates getting a slice of an array of strings, finding
the index of one of the strings in the slice, and then using that index
in the original array.</p>

<pre><code class="language-swift">let streets = [&quot;Adams&quot;, &quot;Bryant&quot;, &quot;Channing&quot;, &quot;Douglas&quot;, &quot;Evarts&quot;]
let streetsSlice = streets[2 ..&lt; streets.endIndex]
print(streetsSlice)
// Prints &quot;[&quot;Channing&quot;, &quot;Douglas&quot;, &quot;Evarts&quot;]&quot;

let index = streetsSlice.index(of: &quot;Evarts&quot;)    // 4
print(streets[index!])
// Prints &quot;Evarts&quot;</code></pre>

<p><strong><code>bounds</code>:</strong>  A range of the collection&#39;s indices. The bounds of
  the range must be valid indices of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(bounds: Range&lt;DictionaryIndex&lt;Key, Value&gt;&gt;) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt; { get }</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>    
</div></div>
</div>


<h3>Instance Methods</h3>
<div class="declaration" id="func-excleq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-excleq_rhs_">func !=(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-excleq_rhs_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func !=(lhs: [Key : Value], rhs: [Key : Value]) -&gt; Bool</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-eqeq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-eqeq_rhs_">func ==(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-eqeq_rhs_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func ==(lhs: [Key : Value], rhs: [Key : Value]) -&gt; Bool</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-contains-where_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-contains-where_">func contains(<wbr>where:)</a>
        
<div class="comment collapse" id="comment-func-contains-where_"><div class="p">
    <p>Returns a Boolean value indicating whether the sequence contains an
element that satisfies the given predicate.</p>

<p>You can use the predicate to check for an element of a type that
doesn&#39;t conform to the <code>Equatable</code> protocol, such as the
<code>HTTPResponse</code> enumeration in this example.</p>

<pre><code class="language-swift">enum HTTPResponse {
    case ok
    case error(Int)
}

let lastThreeResponses: [HTTPResponse] = [.ok, .ok, .error(404)]
let hadError = lastThreeResponses.contains { element in
    if case .error = element {
        return true
    } else {
        return false
    }
}
// &#39;hadError&#39; == true</code></pre>

<p>Alternatively, a predicate can be satisfied by a range of <code>Equatable</code>
elements or a general condition. This example shows how you can check an
array for an expense greater than $100.</p>

<pre><code class="language-swift">let expenses = [21.37, 55.21, 9.32, 10.18, 388.77, 11.41]
let hasBigPurchase = expenses.contains { $0 &gt; 100 }
// &#39;hasBigPurchase&#39; == true</code></pre>

<p><strong><code>predicate</code>:</strong>  A closure that takes an element of the sequence
  as its argument and returns a Boolean value that indicates whether
  the passed element represents a match.
<strong>Returns:</strong> <code>true</code> if the sequence contains an element that satisfies
  <code>predicate</code>; otherwise, <code>false</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func contains(where predicate: ((key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-distance-from_to_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-distance-from_to_">func distance(<wbr>from:<wbr>to:)</a>
        
<div class="comment collapse" id="comment-func-distance-from_to_"><div class="p">
    <p>Returns the distance between two indices.</p>

<p>Unless the collection conforms to the <code>BidirectionalCollection</code> protocol,
<code>start</code> must be less than or equal to <code>end</code>.</p>

<p><strong>Parameters:</strong>
  <strong>start:</strong> A valid index of the collection.
  <strong>end:</strong> Another valid index of the collection. If <code>end</code> is equal to
    <code>start</code>, the result is zero.
<strong>Returns:</strong> The distance between <code>start</code> and <code>end</code>. The result can be
  negative only if the collection conforms to the
  <code>BidirectionalCollection</code> protocol.</p>

<p><strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the
  resulting distance.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func distance(from start: DictionaryIndex&lt;Key, Value&gt;, to end: DictionaryIndex&lt;Key, Value&gt;) -&gt; DictionaryIndex&lt;Key, Value&gt;Distance</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-dropfirst">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-dropfirst">func dropFirst()</a>
        
<div class="comment collapse" id="comment-func-dropfirst"><div class="p">
    <p>Returns a subsequence containing all but the first element of the
sequence.</p>

<p>The following example drops the first element from an array of integers.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.dropFirst())
// Prints &quot;[2, 3, 4, 5]&quot;</code></pre>

<p>If the sequence has no elements, the result is an empty subsequence.</p>

<pre><code class="language-swift">let empty: [Int] = []
print(empty.dropFirst())
// Prints &quot;[]&quot;</code></pre>

<p><strong>Returns:</strong> A subsequence starting after the first element of the
  sequence.</p>

<p><strong>Complexity:</strong> O(1)</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func dropFirst() -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-dropfirst_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-dropfirst_">func dropFirst(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-dropfirst_"><div class="p">
    <p>Returns a subsequence containing all but the given number of initial
elements.</p>

<p>If the number of elements to drop exceeds the number of elements in
the collection, the result is an empty subsequence.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.dropFirst(2))
// Prints &quot;[3, 4, 5]&quot;
print(numbers.dropFirst(10))
// Prints &quot;[]&quot;</code></pre>

<p><strong><code>n</code>:</strong>  The number of elements to drop from the beginning of
  the collection. <code>n</code> must be greater than or equal to zero.
<strong>Returns:</strong> A subsequence starting after the specified number of
  elements.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the number of elements to drop from
  the beginning of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func dropFirst(_ n: Int) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-droplast">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-droplast">func dropLast()</a>
        
<div class="comment collapse" id="comment-func-droplast"><div class="p">
    <p>Returns a subsequence containing all but the last element of the
sequence.</p>

<p>The sequence must be finite. If the sequence has no elements, the result
is an empty subsequence.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.dropLast())
// Prints &quot;[1, 2, 3, 4]&quot;</code></pre>

<p>If the sequence has no elements, the result is an empty subsequence.</p>

<pre><code class="language-swift">let empty: [Int] = []
print(empty.dropLast())
// Prints &quot;[]&quot;</code></pre>

<p><strong>Returns:</strong> A subsequence leaving off the last element of the sequence.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the length of the sequence.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func dropLast() -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-droplast_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-droplast_">func dropLast(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-droplast_"><div class="p">
    <p>Returns a subsequence containing all but the specified number of final
elements.</p>

<p>If the number of elements to drop exceeds the number of elements in the
collection, the result is an empty subsequence.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.dropLast(2))
// Prints &quot;[1, 2, 3]&quot;
print(numbers.dropLast(10))
// Prints &quot;[]&quot;</code></pre>

<p><strong><code>n</code>:</strong>  The number of elements to drop off the end of the
  collection. <code>n</code> must be greater than or equal to zero.
<strong>Returns:</strong> A subsequence that leaves off the specified number of elements
  at the end.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the length of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func dropLast(_ n: Int) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-elementsequal_by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-elementsequal_by_">func elementsEqual(<wbr>_:<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-elementsequal_by_"><div class="p">
    <p>Returns a Boolean value indicating whether this sequence and another
sequence contain equivalent elements, using the given predicate as the
equivalence test.</p>

<p>At least one of the sequences must be finite.</p>

<p>The predicate must be a <em>equivalence relation</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areEquivalent(a, a)</code> is always <code>true</code>. (Reflexivity)</li><li><code>areEquivalent(a, b)</code> implies <code>areEquivalent(b, a)</code>. (Symmetry)</li><li>If <code>areEquivalent(a, b)</code> and <code>areEquivalent(b, c)</code> are both <code>true</code>, then
<code>areEquivalent(a, c)</code> is also <code>true</code>. (Transitivity)</li></ul>

<p><strong>Parameters:</strong>
  <strong>other:</strong> A sequence to compare to this sequence.
  <strong>areEquivalent:</strong> A predicate that returns <code>true</code> if its two arguments
    are equivalent; otherwise, <code>false</code>.
<strong>Returns:</strong> <code>true</code> if this sequence and <code>other</code> contain equivalent items,
  using <code>areEquivalent</code> as the equivalence test; otherwise, <code>false.</code></p>

<p><strong>See Also:</strong> <code>elementsEqual(_:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func elementsEqual&lt;OtherSequence where OtherSequence : Sequence, OtherSequence.Iterator.Element == Iterator.Element&gt;(_ other: OtherSequence, by areEquivalent: ((key: Key, value: Value), (key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-enumerated">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-enumerated">func enumerated()</a>
        
<div class="comment collapse" id="comment-func-enumerated"><div class="p">
    <p>Returns a sequence of pairs (<em>n</em>, <em>x</em>), where <em>n</em> represents a
consecutive integer starting at zero, and <em>x</em> represents an element of
the sequence.</p>

<p>This example enumerates the characters of the string &quot;Swift&quot; and prints
each character along with its place in the string.</p>

<pre><code class="language-swift">for (n, c) in &quot;Swift&quot;.characters.enumerated() {
    print(&quot;\(n): &#39;\(c)&#39;&quot;)
}
// Prints &quot;0: &#39;S&#39;&quot;
// Prints &quot;1: &#39;w&#39;&quot;
// Prints &quot;2: &#39;i&#39;&quot;
// Prints &quot;3: &#39;f&#39;&quot;
// Prints &quot;4: &#39;t&#39;&quot;</code></pre>

<p>When enumerating a collection, the integer part of each pair is a counter
for the enumeration, not necessarily the index of the paired value.
These counters can only be used as indices in instances of zero-based,
integer-indexed collections, such as <code>Array</code> and <code>ContiguousArray</code>. For
other collections the counters may be out of range or of the wrong type
to use as an index. To iterate over the elements of a collection with its
indices, use the <code>zip(_:_:)</code> function.</p>

<p>This example iterates over the indices and elements of a set, building a
list of indices of names with five or fewer letters.</p>

<pre><code class="language-swift">let names: Set = [&quot;Sofia&quot;, &quot;Camilla&quot;, &quot;Martina&quot;, &quot;Mateo&quot;, &quot;Nicolás&quot;]
var shorterIndices: [SetIndex&lt;String&gt;] = []
for (i, name) in zip(names.indices, names) {
    if name.characters.count &lt;= 5 {
        shorterIndices.append(i)
    }
}</code></pre>

<p>Now that the <code>shorterIndices</code> array holds the indices of the shorter
names in the <code>names</code> set, you can use those indices to access elements in
the set.</p>

<pre><code class="language-swift">for i in shorterIndices {
    print(names[i])
}
// Prints &quot;Sofia&quot;
// Prints &quot;Mateo&quot;</code></pre>

<p><strong>Returns:</strong> A sequence of pairs enumerating the sequence.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func enumerated() -&gt; EnumeratedSequence&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-filter_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-filter_">func filter(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-filter_"><div class="p">
    <p>Returns an array containing, in order, the elements of the sequence
that satisfy the given predicate.</p>

<p>In this example, <code>filter</code> is used to include only names shorter than
five characters.</p>

<pre><code class="language-swift">let cast = [&quot;Vivien&quot;, &quot;Marlon&quot;, &quot;Kim&quot;, &quot;Karl&quot;]
let shortNames = cast.filter { $0.characters.count &lt; 5 }
print(shortNames)
// Prints &quot;[&quot;Kim&quot;, &quot;Karl&quot;]&quot;</code></pre>

<p><strong><code>shouldInclude</code>:</strong>  A closure that takes an element of the
  sequence as its argument and returns a Boolean value indicating
  whether the element should be included in the returned array.
<strong>Returns:</strong> An array of the elements that <code>includeElement</code> allowed.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func filter(_ isIncluded: ((key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; [(key: Key, value: Value)]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-first-where_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-first-where_">func first(<wbr>where:)</a>
        
<div class="comment collapse" id="comment-func-first-where_"><div class="p">
    <p>Returns the first element of the sequence that satisfies the given
predicate or nil if no such element is found.</p>

<p><strong><code>predicate</code>:</strong>  A closure that takes an element of the
  sequence as its argument and returns a Boolean value indicating
  whether the element is a match.
<strong>Returns:</strong> The first match or <code>nil</code> if there was no match.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func first(where predicate: ((key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; (key: Key, value: Value)?</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-flatmap-elementofresult_-self-iterator-element-throws-elementofresult">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-flatmap-elementofresult_-self-iterator-element-throws-elementofresult">func flatMap&lt;ElementOfResult&gt;(<wbr>_: ((<wbr>key:<wbr> Key, value: Value)) throws -&gt; ElementOfResult?)</a>
        
<div class="comment collapse" id="comment-func-flatmap-elementofresult_-self-iterator-element-throws-elementofresult"><div class="p">
    <p>Returns an array containing the non-<code>nil</code> results of calling the given
transformation with each element of this sequence.</p>

<p>Use this method to receive an array of nonoptional values when your
transformation produces an optional value.</p>

<p>In this example, note the difference in the result of using <code>map</code> and
<code>flatMap</code> with a transformation that returns an optional <code>Int</code> value.</p>

<pre><code class="language-swift">let possibleNumbers = [&quot;1&quot;, &quot;2&quot;, &quot;three&quot;, &quot;///4///&quot;, &quot;5&quot;]

let mapped: [Int?] = numbers.map { str in Int(str) }
// [1, 2, nil, nil, 5]

let flatMapped: [Int] = numbers.flatMap { str in Int(str) }
// [1, 2, 5]</code></pre>

<p><strong><code>transform</code>:</strong>  A closure that accepts an element of this
  sequence as its argument and returns an optional value.
<strong>Returns:</strong> An array of the non-<code>nil</code> results of calling <code>transform</code>
  with each element of the sequence.</p>

<p><strong>Complexity:</strong> O(<em>m</em> + <em>n</em>), where <em>m</em> is the length of this sequence
  and <em>n</em> is the length of the result.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func flatMap&lt;ElementOfResult&gt;(_ transform: ((key: Key, value: Value)) throws -&gt; ElementOfResult?) rethrows -&gt; [ElementOfResult]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-flatmap-segmentofresult_-sequence_-self-iterator-element-throws-segmentofresult">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-flatmap-segmentofresult_-sequence_-self-iterator-element-throws-segmentofresult">func <wbr>flatMap&lt;SegmentOfResult : Sequence&gt;(<wbr>_: ((<wbr>key:<wbr> Key, value: Value)) throws -&gt; SegmentOfResult)</a>
        
<div class="comment collapse" id="comment-func-flatmap-segmentofresult_-sequence_-self-iterator-element-throws-segmentofresult"><div class="p">
    <p>Returns an array containing the concatenated results of calling the
given transformation with each element of this sequence.</p>

<p>Use this method to receive a single-level collection when your
transformation produces a sequence or collection for each element.</p>

<p>In this example, note the difference in the result of using <code>map</code> and
<code>flatMap</code> with a transformation that returns an array.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4]

let mapped = numbers.map { Array(count: $0, repeatedValue: $0) }
// [[1], [2, 2], [3, 3, 3], [4, 4, 4, 4]]

let flatMapped = numbers.flatMap { Array(count: $0, repeatedValue: $0) }
// [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]</code></pre>

<p>In fact, <code>s.flatMap(transform)</code>  is equivalent to
<code>Array(s.map(transform).joined())</code>.</p>

<p><strong><code>transform</code>:</strong>  A closure that accepts an element of this
  sequence as its argument and returns a sequence or collection.
<strong>Returns:</strong> The resulting flattened array.</p>

<p><strong>Complexity:</strong> O(<em>m</em> + <em>n</em>), where <em>m</em> is the length of this sequence
  and <em>n</em> is the length of the result.
<strong>See Also:</strong> <code>joined()</code>, <code>map(_:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func flatMap&lt;SegmentOfResult : Sequence&gt;(_ transform: ((key: Key, value: Value)) throws -&gt; SegmentOfResult) rethrows -&gt; [SegmentOfResult.Iterator.Element]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-foreach_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-foreach_">func forEach(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-foreach_"><div class="p">
    <p>Calls the given closure on each element in the sequence in the same order
as a <code>for</code>-<code>in</code> loop.</p>

<p>The two loops in the following example produce the same output:</p>

<pre><code class="language-swift">let numberWords = [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;]
for word in numberWords {
    print(word)
}
// Prints &quot;one&quot;
// Prints &quot;two&quot;
// Prints &quot;three&quot;

numberWords.forEach { word in
    print(word)
}
// Same as above</code></pre>

<p>Using the <code>forEach</code> method is distinct from a <code>for</code>-<code>in</code> loop in two
important ways:</p>

<ol><li>You cannot use a <code>break</code> or <code>continue</code> statement to exit the current
call of the <code>body</code> closure or skip subsequent calls.</li><li>Using the <code>return</code> statement in the <code>body</code> closure will exit only from
the current call to <code>body</code>, not from any outer scope, and won&#39;t skip
subsequent calls.</li></ol>

<p><strong><code>body</code>:</strong>  A closure that takes an element of the sequence as a
  parameter.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func forEach(_ body: ((key: Key, value: Value)) throws -&gt; Swift.Void) rethrows</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-formindex_offsetby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-formindex_offsetby_">func formIndex(<wbr>_:<wbr>offsetBy:)</a>
        
<div class="comment collapse" id="comment-func-formindex_offsetby_"><div class="p">
    <p>Offsets the given index by the specified distance.</p>

<p>The value passed as <code>n</code> must not offset <code>i</code> beyond the <code>endIndex</code> or
before the <code>startIndex</code> of this collection.</p>

<p><strong>Parameters:</strong>
  <strong>i:</strong> A valid index of the collection.
  <strong>n:</strong> The distance to offset <code>i</code>. <code>n</code> must not be negative unless the
    collection conforms to the <code>BidirectionalCollection</code> protocol.</p>

<p><strong>See Also:</strong> <code>index(_:offsetBy:)</code>, <code>formIndex(_:offsetBy:limitedBy:)</code>
<strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the absolute
  value of <code>n</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func formIndex(_ i: inout DictionaryIndex&lt;Key, Value&gt;, offsetBy n: DictionaryIndex&lt;Key, Value&gt;Distance)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-formindex_offsetby_limitedby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-formindex_offsetby_limitedby_">func formIndex(<wbr>_:<wbr>offsetBy:<wbr>limitedBy:)</a>
        
<div class="comment collapse" id="comment-func-formindex_offsetby_limitedby_"><div class="p">
    <p>Offsets the given index by the specified distance, or so that it equals
the given limiting index.</p>

<p>The value passed as <code>n</code> must not offset <code>i</code> beyond the <code>endIndex</code> or
before the <code>startIndex</code> of this collection, unless the index passed as
<code>limit</code> prevents offsetting beyond those bounds.</p>

<p><strong>Parameters:</strong>
  <strong>i:</strong> A valid index of the collection.
  <strong>n:</strong> The distance to offset <code>i</code>. <code>n</code> must not be negative unless the
    collection conforms to the <code>BidirectionalCollection</code> protocol.
<strong>Returns:</strong> <code>true</code> if <code>i</code> has been offset by exactly <code>n</code> steps without
  going beyond <code>limit</code>; otherwise, <code>false</code>. When the return value is
  <code>false</code>, the value of <code>i</code> is equal to <code>limit</code>.</p>

<p><strong>See Also:</strong> <code>index(_:offsetBy:)</code>, <code>formIndex(_:offsetBy:limitedBy:)</code>
<strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the absolute
  value of <code>n</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func formIndex(_ i: inout DictionaryIndex&lt;Key, Value&gt;, offsetBy n: DictionaryIndex&lt;Key, Value&gt;Distance, limitedBy limit: DictionaryIndex&lt;Key, Value&gt;) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-formindex-after_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-formindex-after_">func formIndex(<wbr>after:)</a>
        
<div class="comment collapse" id="comment-func-formindex-after_"><div class="p">
    <p>Replaces the given index with its successor.</p>

<p><strong><code>i</code>:</strong>  A valid index of the collection. <code>i</code> must be less than
  <code>endIndex</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func formIndex(after i: inout DictionaryIndex&lt;Key, Value&gt;)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-index_offsetby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-index_offsetby_">func index(<wbr>_:<wbr>offsetBy:)</a>
        
<div class="comment collapse" id="comment-func-index_offsetby_"><div class="p">
    <p>Returns an index that is the specified distance from the given index.</p>

<p>The following example obtains an index advanced four positions from a
string&#39;s starting index and then prints the character at that position.</p>

<pre><code class="language-swift">let s = &quot;Swift&quot;
let i = s.index(s.startIndex, offsetBy: 4)
print(s[i])
// Prints &quot;t&quot;</code></pre>

<p>The value passed as <code>n</code> must not offset <code>i</code> beyond the <code>endIndex</code> or
before the <code>startIndex</code> of this collection.</p>

<p><strong>Parameters:</strong>
  <strong>i:</strong> A valid index of the collection.
  <strong>n:</strong> The distance to offset <code>i</code>. <code>n</code> must not be negative unless the
    collection conforms to the <code>BidirectionalCollection</code> protocol.
<strong>Returns:</strong> An index offset by <code>n</code> from the index <code>i</code>. If <code>n</code> is positive,
  this is the same value as the result of <code>n</code> calls to <code>index(after:)</code>.
  If <code>n</code> is negative, this is the same value as the result of <code>-n</code> calls
  to <code>index(before:)</code>.</p>

<p><strong>See Also:</strong> <code>index(_:offsetBy:limitedBy:)</code>, <code>formIndex(_:offsetBy:)</code>
<strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the absolute
  value of <code>n</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func index(_ i: DictionaryIndex&lt;Key, Value&gt;, offsetBy n: DictionaryIndex&lt;Key, Value&gt;Distance) -&gt; DictionaryIndex&lt;Key, Value&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-index_offsetby_limitedby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-index_offsetby_limitedby_">func index(<wbr>_:<wbr>offsetBy:<wbr>limitedBy:)</a>
        
<div class="comment collapse" id="comment-func-index_offsetby_limitedby_"><div class="p">
    <p>Returns an index that is the specified distance from the given index,
unless that distance is beyond a given limiting index.</p>

<p>The following example obtains an index advanced four positions from a
string&#39;s starting index and then prints the character at that position.
The operation doesn&#39;t require going beyond the limiting <code>s.endIndex</code>
value, so it succeeds.</p>

<pre><code class="language-swift">let s = &quot;Swift&quot;
if let i = s.index(s.startIndex, offsetBy: 4, limitedBy: s.endIndex) {
    print(s[i])
}
// Prints &quot;t&quot;</code></pre>

<p>The next example attempts to retrieve an index six positions from
<code>s.startIndex</code> but fails, because that distance is beyond the index
passed as <code>limit</code>.</p>

<pre><code class="language-swift">let j = s.index(s.startIndex, offsetBy: 6, limitedBy: s.endIndex)
print(j)
// Prints &quot;nil&quot;</code></pre>

<p>The value passed as <code>n</code> must not offset <code>i</code> beyond the <code>endIndex</code> or
before the <code>startIndex</code> of this collection, unless the index passed as
<code>limit</code> prevents offsetting beyond those bounds.</p>

<p><strong>Parameters:</strong>
  <strong>i:</strong> A valid index of the collection.
  <strong>n:</strong> The distance to offset <code>i</code>. <code>n</code> must not be negative unless the
    collection conforms to the <code>BidirectionalCollection</code> protocol.
  <strong>limit:</strong> A valid index of the collection to use as a limit. If <code>n &gt; 0</code>,
    a limit that is less than <code>i</code> has no effect. Likewise, if <code>n &lt; 0</code>, a
    limit that is greater than <code>i</code> has no effect.
<strong>Returns:</strong> An index offset by <code>n</code> from the index <code>i</code>, unless that index
  would be beyond <code>limit</code> in the direction of movement. In that case,
  the method returns <code>nil</code>.</p>

<p><strong>See Also:</strong> <code>index(_:offsetBy:)</code>, <code>formIndex(_:offsetBy:limitedBy:)</code>
<strong>Complexity:</strong> O(1) if the collection conforms to
  <code>RandomAccessCollection</code>; otherwise, O(<em>n</em>), where <em>n</em> is the absolute
  value of <code>n</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func index(_ i: DictionaryIndex&lt;Key, Value&gt;, offsetBy n: DictionaryIndex&lt;Key, Value&gt;Distance, limitedBy limit: DictionaryIndex&lt;Key, Value&gt;) -&gt; DictionaryIndex&lt;Key, Value&gt;?</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Indexable/"><code>Indexable</code></a>    
</div></div>
</div>
<div class="declaration" id="func-index-after_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-index-after_">func index(<wbr>after:)</a>
        
<div class="comment collapse" id="comment-func-index-after_"><div class="p">
    <p>Returns the position immediately after the given index.</p>

<p><strong><code>i</code>:</strong>  A valid index of the collection. <code>i</code> must be less than
  <code>endIndex</code>.
<strong>Returns:</strong> The index value immediately after <code>i</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func index(after i: DictionaryIndex&lt;Key, Value&gt;) -&gt; DictionaryIndex&lt;Key, Value&gt;</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-index-forkey_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-index-forkey_">func index(<wbr>forKey:)</a>
        
<div class="comment collapse" id="comment-func-index-forkey_"><div class="p">
    <p>Returns the index for the given key.</p>

<p>If the given key is found in the dictionary, this method returns an index
into the dictionary that corresponds with the key-value pair.</p>

<pre><code class="language-swift">let countryCodes = [&quot;BR&quot;: &quot;Brazil&quot;, &quot;GH&quot;: &quot;Ghana&quot;, &quot;JP&quot;: &quot;Japan&quot;]
let index = countryCodes.index(forKey: &quot;JP&quot;)

print(&quot;Country code for \(countryCodes[index!].value): &#39;\(countryCodes[index!].key)&#39;.&quot;)
// Prints &quot;Country code for Japan: &#39;JP&#39;.&quot;</code></pre>

<p><strong><code>key</code>:</strong>  The key to find in the dictionary.
<strong>Returns:</strong> The index for <code>key</code> and its associated value if <code>key</code> is in
  the dictionary; otherwise, <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func index(forKey key: Key) -&gt; DictionaryIndex&lt;Key, Value&gt;?</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-index-where_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-index-where_">func index(<wbr>where:)</a>
        
<div class="comment collapse" id="comment-func-index-where_"><div class="p">
    <p>Returns the first index in which an element of the collection satisfies
the given predicate.</p>

<p>You can use the predicate to find an element of a type that doesn&#39;t
conform to the <code>Equatable</code> protocol or to find an element that matches
particular criteria. Here&#39;s an example that finds a student name that
begins with the letter &quot;A&quot;:</p>

<pre><code class="language-swift">let students = [&quot;Kofi&quot;, &quot;Abena&quot;, &quot;Peter&quot;, &quot;Kweku&quot;, &quot;Akosua&quot;]
if let i = students.index(where: { $0.hasPrefix(&quot;A&quot;) }) {
    print(&quot;\(students[i]) starts with &#39;A&#39;!&quot;)
}
// Prints &quot;Abena starts with &#39;A&#39;!&quot;</code></pre>

<p><strong><code>predicate</code>:</strong>  A closure that takes an element as its argument
  and returns a Boolean value that indicates whether the passed element
  represents a match.
<strong>Returns:</strong> The index of the first element for which <code>predicate</code> returns
  <code>true</code>. If no elements in the collection satisfy the given predicate,
  returns <code>nil</code>.</p>

<p><strong>See Also:</strong> <code>index(of:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func index(where predicate: ((key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; DictionaryIndex&lt;Key, Value&gt;?</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-lexicographicallyprecedes_by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-lexicographicallyprecedes_by_">func lexicographicallyPrecedes(<wbr>_:<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-lexicographicallyprecedes_by_"><div class="p">
    <p>Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the given
predicate to compare elements.</p>

<p>The predicate must be a <em>strict weak ordering</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areInIncreasingOrder(a, a)</code> is always <code>false</code>. (Irreflexivity)</li><li>If <code>areInIncreasingOrder(a, b)</code> and <code>areInIncreasingOrder(b, c)</code> are
both <code>true</code>, then <code>areInIncreasingOrder(a, c)</code> is also
<code>true</code>. (Transitive comparability)</li><li>Two elements are <em>incomparable</em> if neither is ordered before the other
according to the predicate. If <code>a</code> and <code>b</code> are incomparable, and <code>b</code>
and <code>c</code> are incomparable, then <code>a</code> and <code>c</code> are also incomparable.
(Transitive incomparability)</li></ul>

<p><strong>Parameters:</strong>
  <strong>other:</strong> A sequence to compare to this sequence.
  <strong>areInIncreasingOrder:</strong>  A predicate that returns <code>true</code> if its first
    argument should be ordered before its second argument; otherwise,
    <code>false</code>.
<strong>Returns:</strong> <code>true</code> if this sequence precedes <code>other</code> in a dictionary
  ordering as ordered by <code>areInIncreasingOrder</code>; otherwise, <code>false</code>.</p>

<p><strong>Note:</strong> This method implements the mathematical notion of lexicographical
  ordering, which has no connection to Unicode.  If you are sorting
  strings to present to the end user, use <code>String</code> APIs that perform
  localized comparison instead.
<strong>See Also:</strong> <code>lexicographicallyPrecedes(_:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func lexicographicallyPrecedes&lt;OtherSequence where OtherSequence : Sequence, OtherSequence.Iterator.Element == Iterator.Element&gt;(_ other: OtherSequence, by areInIncreasingOrder: ((key: Key, value: Value), (key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration" id="func-makeiterator">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-makeiterator">func makeIterator()</a>
        
<div class="comment collapse" id="comment-func-makeiterator"><div class="p">
    <p>Returns an iterator over the dictionary&#39;s key-value pairs.</p>

<p>Iterating over a dictionary yields the key-value pairs as two-element
tuples. You can decompose the tuple in a <code>for</code>-<code>in</code> loop, which calls
<code>makeIterator()</code> behind the scenes, or when calling the iterator&#39;s
<code>next()</code> method directly.</p>

<pre><code class="language-swift">let hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]
for (name, hueValue) in hues {
    print(&quot;The hue of \(name) is \(hueValue).&quot;)
}
// Prints &quot;The hue of Heliotrope is 296.&quot;
// Prints &quot;The hue of Coral is 16.&quot;
// Prints &quot;The hue of Aquamarine is 156.&quot;</code></pre>

<p><strong>Returns:</strong> An iterator over the dictionary with elements of type
  <code>(key: Key, value: Value)</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func makeIterator() -&gt; DictionaryIterator&lt;Key, Value&gt;</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-map_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-map_">func map(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-map_"><div class="p">
    <p>Returns an array containing the results of mapping the given closure
over the sequence&#39;s elements.</p>

<p>In this example, <code>map</code> is used first to convert the names in the array
to lowercase strings and then to count their characters.</p>

<pre><code class="language-swift">let cast = [&quot;Vivien&quot;, &quot;Marlon&quot;, &quot;Kim&quot;, &quot;Karl&quot;]
let lowercaseNames = cast.map { $0.lowercaseString }
// &#39;lowercaseNames&#39; == [&quot;vivien&quot;, &quot;marlon&quot;, &quot;kim&quot;, &quot;karl&quot;]
let letterCounts = cast.map { $0.characters.count }
// &#39;letterCounts&#39; == [6, 6, 3, 4]</code></pre>

<p><strong><code>transform</code>:</strong>  A mapping closure. <code>transform</code> accepts an
  element of this sequence as its parameter and returns a transformed
  value of the same or of a different type.
<strong>Returns:</strong> An array containing the transformed elements of this
  sequence.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func map&lt;T&gt;(_ transform: ((key: Key, value: Value)) throws -&gt; T) rethrows -&gt; [T]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-max-by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-max-by_">@warn_unqualified_access
     func max(<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-max-by_"><div class="p">
    <p>Returns the maximum element in the sequence, using the given predicate
as the comparison between elements.</p>

<p>The predicate must be a <em>strict weak ordering</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areInIncreasingOrder(a, a)</code> is always <code>false</code>. (Irreflexivity)</li><li>If <code>areInIncreasingOrder(a, b)</code> and <code>areInIncreasingOrder(b, c)</code> are
both <code>true</code>, then <code>areInIncreasingOrder(a, c)</code> is also
<code>true</code>. (Transitive comparability)</li><li>Two elements are <em>incomparable</em> if neither is ordered before the other
according to the predicate. If <code>a</code> and <code>b</code> are incomparable, and <code>b</code>
and <code>c</code> are incomparable, then <code>a</code> and <code>c</code> are also incomparable.
(Transitive incomparability)</li></ul>

<p>This example shows how to use the <code>max(by:)</code> method on a
dictionary to find the key-value pair with the highest value.</p>

<pre><code class="language-swift">let hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]
let greatestHue = hues.max { a, b in a.value &lt; b.value }
print(greatestHue)
// Prints &quot;Optional((&quot;Heliotrope&quot;, 296))&quot;</code></pre>

<p><strong><code>areInIncreasingOrder</code>:</strong>   A predicate that returns <code>true</code> if its
  first argument should be ordered before its second argument;
  otherwise, <code>false</code>.
<strong>Returns:</strong> The sequence&#39;s maximum element if the sequence is not empty;
  otherwise, <code>nil</code>.</p>

<p><strong>See Also:</strong> <code>max()</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">@warn_unqualified_access
     func max(by areInIncreasingOrder: ((key: Key, value: Value), (key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; (key: Key, value: Value)?</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-min-by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-min-by_">@warn_unqualified_access
     func min(<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-min-by_"><div class="p">
    <p>Returns the minimum element in the sequence, using the given predicate as
the comparison between elements.</p>

<p>The predicate must be a <em>strict weak ordering</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areInIncreasingOrder(a, a)</code> is always <code>false</code>. (Irreflexivity)</li><li>If <code>areInIncreasingOrder(a, b)</code> and <code>areInIncreasingOrder(b, c)</code> are
both <code>true</code>, then <code>areInIncreasingOrder(a, c)</code> is also
<code>true</code>. (Transitive comparability)</li><li>Two elements are <em>incomparable</em> if neither is ordered before the other
according to the predicate. If <code>a</code> and <code>b</code> are incomparable, and <code>b</code>
and <code>c</code> are incomparable, then <code>a</code> and <code>c</code> are also incomparable.
(Transitive incomparability)</li></ul>

<p>This example shows how to use the <code>min(by:)</code> method on a
dictionary to find the key-value pair with the lowest value.</p>

<pre><code class="language-swift">let hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]
let leastHue = hues.min { a, b in a.value &lt; b.value }
print(leastHue)
// Prints &quot;Optional((&quot;Coral&quot;, 16))&quot;</code></pre>

<p><strong><code>areInIncreasingOrder</code>:</strong>  A predicate that returns <code>true</code>
  if its first argument should be ordered before its second
  argument; otherwise, <code>false</code>.
<strong>Returns:</strong> The sequence&#39;s minimum element, according to
  <code>areInIncreasingOrder</code>. If the sequence has no elements, returns
  <code>nil</code>.</p>

<p><strong>See Also:</strong> <code>min()</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">@warn_unqualified_access
     func min(by areInIncreasingOrder: ((key: Key, value: Value), (key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; (key: Key, value: Value)?</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration" id="func-popfirst">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-popfirst">mutating func popFirst()</a>
        
<div class="comment collapse" id="comment-func-popfirst"><div class="p">
    <p>Removes and returns the first key-value pair of the dictionary if the
dictionary isn&#39;t empty.</p>

<p>The first element of the dictionary is not necessarily the first element
added. Don&#39;t expect any particular ordering of key-value pairs.</p>

<p><strong>Returns:</strong> The first key-value pair of the dictionary if the dictionary
  is not empty; otherwise, <code>nil</code>.</p>

<p><strong>Complexity:</strong> Averages to O(1) over many calls to <code>popFirst()</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func popFirst() -&gt; (key: Key, value: Value)?</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-prefix_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-prefix_">func prefix(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-prefix_"><div class="p">
    <p>Returns a subsequence, up to the specified maximum length, containing
the initial elements of the collection.</p>

<p>If the maximum length exceeds the number of elements in the collection,
the result contains all the elements in the collection.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.prefix(2))
// Prints &quot;[1, 2]&quot;
print(numbers.prefix(10))
// Prints &quot;[1, 2, 3, 4, 5]&quot;</code></pre>

<p><strong><code>maxLength</code>:</strong>  The maximum number of elements to return.
  <code>maxLength</code> must be greater than or equal to zero.
<strong>Returns:</strong> A subsequence starting at the beginning of this collection
  with at most <code>maxLength</code> elements.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func prefix(_ maxLength: Int) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-prefix-through_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-prefix-through_">func prefix(<wbr>through:)</a>
        
<div class="comment collapse" id="comment-func-prefix-through_"><div class="p">
    <p>Returns a subsequence from the start of the collection through the
specified position.</p>

<p>The resulting subsequence <em>includes</em> the element at the position <code>end</code>. 
The following example searches for the index of the number <code>40</code> in an
array of integers, and then prints the prefix of the array up to, and
including, that index:</p>

<pre><code class="language-swift">let numbers = [10, 20, 30, 40, 50, 60]
if let i = numbers.index(of: 40) {
    print(numbers.prefix(through: i))
}
// Prints &quot;[10, 20, 30, 40]&quot;</code></pre>

<p><strong><code>end</code>:</strong>  The index of the last element to include in the
  resulting subsequence. <code>end</code> must be a valid index of the collection
  that is not equal to the <code>endIndex</code> property.
<strong>Returns:</strong> A subsequence up to, and including, the <code>end</code> position.</p>

<p><strong>Complexity:</strong> O(1)
<strong>See Also:</strong> <code>prefix(upTo:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func prefix(through position: DictionaryIndex&lt;Key, Value&gt;) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-prefix-upto_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-prefix-upto_">func prefix(<wbr>upTo:)</a>
        
<div class="comment collapse" id="comment-func-prefix-upto_"><div class="p">
    <p>Returns a subsequence from the start of the collection up to, but not
including, the specified position.</p>

<p>The resulting subsequence <em>does not include</em> the element at the position
<code>end</code>. The following example searches for the index of the number <code>40</code>
in an array of integers, and then prints the prefix of the array up to,
but not including, that index:</p>

<pre><code class="language-swift">let numbers = [10, 20, 30, 40, 50, 60]
if let i = numbers.index(of: 40) {
    print(numbers.prefix(upTo: i))
}
// Prints &quot;[10, 20, 30]&quot;</code></pre>

<p>Passing the collection&#39;s starting index as the <code>end</code> parameter results in
an empty subsequence.</p>

<pre><code class="language-swift">print(numbers.prefix(upTo: numbers.startIndex))
// Prints &quot;[]&quot;</code></pre>

<p><strong><code>end</code>:</strong>  The &quot;past the end&quot; index of the resulting subsequence.
  <code>end</code> must be a valid index of the collection.
<strong>Returns:</strong> A subsequence up to, but not including, the <code>end</code> position.</p>

<p><strong>Complexity:</strong> O(1)
<strong>See Also:</strong> <code>prefix(through:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func prefix(upTo end: DictionaryIndex&lt;Key, Value&gt;) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-reduce__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-reduce__">func reduce(<wbr>_:<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-reduce__"><div class="p">
    <p>Returns the result of calling the given combining closure with each
element of this sequence and an accumulating value.</p>

<p>The <code>nextPartialResult</code> closure is called sequentially with an
accumulating value initialized to <code>initialResult</code> and each
element of the sequence. This example shows how to find the sum
of an array of numbers.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4]
let addTwo: (Int, Int) -&gt; Int = { x, y in x + y }
let numberSum = numbers.reduce(0, addTwo)
// &#39;numberSum&#39; == 10</code></pre>

<p>When <code>numbers.reduce(_:_:)</code> is called, the
following steps occur:</p>

<ol><li>The <code>nextPartialResult</code> closure is called with the initial
result and the first element of <code>numbers</code>, returning the sum:
<code>1</code>.</li><li>The closure is called again repeatedly with the previous call&#39;s
return value and each element of the sequence.</li><li>When the sequence is exhausted, the last value returned from the
closure is returned to the caller.</li></ol>

<p><strong>Parameters:</strong>
  <strong>initialResult:</strong> the initial accumulating value.
  <strong>nextPartialResult:</strong> A closure that combines an accumulating
    value and an element of the sequence into a new accumulating
    value, to be used in the next call of the
    <code>nextPartialResult</code> closure or returned to the caller.
<strong>Returns:</strong> The final accumulated value.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func reduce&lt;Result&gt;(_ initialResult: Result, _ nextPartialResult: (Result, (key: Key, value: Value)) throws -&gt; Result) rethrows -&gt; Result</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration" id="func-remove-at_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-remove-at_">mutating func remove(<wbr>at:)</a>
        
<div class="comment collapse" id="comment-func-remove-at_"><div class="p">
    <p>Removes and returns the key-value pair at the specified index.</p>

<p>Calling this method invalidates any existing indices for use with this
dictionary.</p>

<p><strong><code>index</code>:</strong>  The position of the key-value pair to remove. <code>index</code>
  must be a valid index of the dictionary, and must not equal the
  dictionary&#39;s end index.
<strong>Returns:</strong> The key-value pair that correspond to <code>index</code>.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the number of key-value pairs in the
  dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func remove(at index: DictionaryIndex&lt;Key, Value&gt;) -&gt; (key: Key, value: Value)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removeall-keepingcapacity_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removeall-keepingcapacity_">mutating func removeAll(<wbr>keepingCapacity:)</a>
        
<div class="comment collapse" id="comment-func-removeall-keepingcapacity_"><div class="p">
    <p>Removes all key-value pairs from the dictionary.</p>

<p>Calling this method invalidates all indices with respect to the
dictionary.</p>

<p><strong><code>keepCapacity</code>:</strong>  Whether the dictionary should keep its
  underlying storage. If you pass <code>true</code>, the operation preserves the
  storage capacity that the collection has, otherwise the underlying
  storage is released.  The default is <code>false</code>.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the number of key-value pairs in the
  dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeAll(keepingCapacity keepCapacity: Bool = default)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removevalue-forkey_-key">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removevalue-forkey_-key">mutating func removeValue(<wbr>forKey: Key)</a>
        
<div class="comment collapse" id="comment-func-removevalue-forkey_-key"><div class="p">
    <p>Removes the given key and its associated value from the dictionary.</p>

<p>If the key is found in the dictionary, this method returns the key&#39;s
associated value. On removal, this method invalidates all indices with
respect to the dictionary.</p>

<pre><code class="language-swift">var hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]
if let value = hues.removeValue(forKey: &quot;Coral&quot;) {
    print(&quot;The value \(value) was removed.&quot;)
}
// Prints &quot;The value 16 was removed.&quot;</code></pre>

<p>If the key isn&#39;t found in the dictionary, <code>removeValue(forKey:)</code> returns
<code>nil</code>.</p>

<pre><code class="language-swift">if let value = hues.removeValueForKey(&quot;Cerise&quot;) {
    print(&quot;The value \(value) was removed.&quot;)
} else {
    print(&quot;No value found for that key.&quot;)
}
// Prints &quot;No value found for that key.&quot;&quot;</code></pre>

<p><strong><code>key</code>:</strong>  The key to remove along with its associated value.
<strong>Returns:</strong> The value that was removed, or <code>nil</code> if the key was not
  present in the dictionary.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the number of key-value pairs in the
  dictionary.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeValue(forKey key: Key) -&gt; Value?</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removevalue-concretekey_-hashable-forkey_-concretekey">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removevalue-concretekey_-hashable-forkey_-concretekey">mutating func <wbr>removeValue&lt;ConcreteKey : Hashable&gt;(<wbr>forKey: ConcreteKey)</a>
        
<div class="comment collapse" id="comment-func-removevalue-concretekey_-hashable-forkey_-concretekey"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeValue&lt;ConcreteKey : Hashable&gt;(forKey key: ConcreteKey) -&gt; Value?</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-reversed">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-reversed">func reversed()</a>
        
<div class="comment collapse" id="comment-func-reversed"><div class="p">
    <p>Returns an array containing the elements of this sequence in reverse
order.</p>

<p>The sequence must be finite.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the length of the sequence.</p>

<p><strong>Returns:</strong> An array containing the elements of this sequence in
  reverse order.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func reversed() -&gt; [(key: Key, value: Value)]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-sorted-by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-sorted-by_">func sorted(<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-sorted-by_"><div class="p">
    <p>Returns the elements of the sequence, sorted using the given
predicate as the comparison between elements.</p>

<p>When you want to sort a sequence of elements that don&#39;t conform to
the <code>Comparable</code> protocol, pass a predicate to this method that returns
<code>true</code> when the first element passed should be ordered before the
second. The elements of the resulting array are ordered according to the
given predicate.</p>

<p>The predicate must be a <em>strict weak ordering</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areInIncreasingOrder(a, a)</code> is always <code>false</code>. (Irreflexivity)</li><li>If <code>areInIncreasingOrder(a, b)</code> and <code>areInIncreasingOrder(b, c)</code> are
both <code>true</code>, then <code>areInIncreasingOrder(a, c)</code> is also <code>true</code>.
(Transitive comparability)</li><li>Two elements are <em>incomparable</em> if neither is ordered before the other
according to the predicate. If <code>a</code> and <code>b</code> are incomparable, and <code>b</code>
and <code>c</code> are incomparable, then <code>a</code> and <code>c</code> are also incomparable.
(Transitive incomparability)</li></ul>

<p>The sorting algorithm is not stable. A nonstable sort may change the
relative order of elements for which <code>areInIncreasingOrder</code> does not
establish an order.</p>

<p>In the following example, the predicate provides an ordering for an array
of a custom <code>HTTPResponse</code> type. The predicate orders errors before
successes and sorts the error responses by their error code.</p>

<pre><code class="language-swift">enum HTTPResponse {
    case ok
    case error(Int)
}

let responses: [HTTPResponse] = [.error(500), .ok, .ok, .error(404), .error(403)]
let sortedResponses = responses.sorted {
    switch ($0, $1) {
    // Order errors by code
    case let (.error(aCode), .error(bCode)):
        return aCode &lt; bCode

    // All successes are equivalent, so none is before any other
    case (.ok, .ok): return false

    // Order errors before successes
    case (.error, .ok): return true
    case (.ok, .error): return false
    }
}
print(sortedResponses)
// Prints &quot;[.error(403), .error(404), .error(500), .ok, .ok]&quot;</code></pre>

<p>You also use this method to sort elements that conform to the
<code>Comparable</code> protocol in descending order. To sort your sequence
in descending order, pass the greater-than operator (<code>&gt;</code>) as the
<code>areInIncreasingOrder</code> parameter.</p>

<pre><code class="language-swift">let students: Set = [&quot;Kofi&quot;, &quot;Abena&quot;, &quot;Peter&quot;, &quot;Kweku&quot;, &quot;Akosua&quot;]
let descendingStudents = students.sorted(by: &gt;)
print(descendingStudents)
// Prints &quot;[&quot;Peter&quot;, &quot;Kweku&quot;, &quot;Kofi&quot;, &quot;Akosua&quot;, &quot;Abena&quot;]&quot;</code></pre>

<p>Calling the related <code>sorted()</code> method is equivalent to calling this
method and passing the less-than operator (<code>&lt;</code>) as the predicate.</p>

<pre><code class="language-swift">print(students.sorted())
// Prints &quot;[&quot;Abena&quot;, &quot;Akosua&quot;, &quot;Kofi&quot;, &quot;Kweku&quot;, &quot;Peter&quot;]&quot;
print(students.sorted(by: &lt;))
// Prints &quot;[&quot;Abena&quot;, &quot;Akosua&quot;, &quot;Kofi&quot;, &quot;Kweku&quot;, &quot;Peter&quot;]&quot;</code></pre>

<p><strong><code>areInIncreasingOrder</code>:</strong>  A predicate that returns <code>true</code> if its first
  argument should be ordered before its second argument; otherwise,
  <code>false</code>.
<strong>Returns:</strong> A sorted array of the sequence&#39;s elements.</p>

<p><strong>See Also:</strong> <code>sorted()</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func sorted(by areInIncreasingOrder: ((key: Key, value: Value), (key: Key, value: Value)) -&gt; Bool) -&gt; [(key: Key, value: Value)]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-split_omittingemptysubsequences_whereseparator_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-split_omittingemptysubsequences_whereseparator_">func split(<wbr>_:<wbr>omittingEmptySubsequences:<wbr>whereSeparator:)</a>
        
<div class="comment collapse" id="comment-func-split_omittingemptysubsequences_whereseparator_"><div class="p">
    <p>Returns the longest possible subsequences of the collection, in order,
that don&#39;t contain elements satisfying the given predicate.</p>

<p>The resulting array consists of at most <code>maxSplits + 1</code> subsequences.
Elements that are used to split the sequence are not returned as part of
any subsequence.</p>

<p>The following examples show the effects of the <code>maxSplits</code> and
<code>omittingEmptySubsequences</code> parameters when splitting a string using a
closure that matches spaces. The first use of <code>split</code> returns each word
that was originally separated by one or more spaces.</p>

<pre><code class="language-swift">let line = &quot;BLANCHE:   I don&#39;t want realism. I want magic!&quot;
print(line.characters.split(whereSeparator: { $0 == &quot; &quot; })
                     .map(String.init))
// Prints &quot;[&quot;BLANCHE:&quot;, &quot;I&quot;, &quot;don\&#39;t&quot;, &quot;want&quot;, &quot;realism.&quot;, &quot;I&quot;, &quot;want&quot;, &quot;magic!&quot;]&quot;</code></pre>

<p>The second example passes <code>1</code> for the <code>maxSplits</code> parameter, so the
original string is split just once, into two new strings.</p>

<pre><code class="language-swift">print(
    line.characters.split(
        maxSplits: 1, whereSeparator: { $0 == &quot; &quot; }
        ).map(String.init))
// Prints &quot;[&quot;BLANCHE:&quot;, &quot;  I don\&#39;t want realism. I want magic!&quot;]&quot;</code></pre>

<p>The final example passes <code>false</code> for the <code>omittingEmptySubsequences</code>
parameter, so the returned array contains empty strings where spaces
were repeated.</p>

<pre><code class="language-swift">print(line.characters.split(omittingEmptySubsequences: false, whereSeparator: { $0 == &quot; &quot; })
                      .map(String.init))
// Prints &quot;[&quot;BLANCHE:&quot;, &quot;&quot;, &quot;&quot;, &quot;I&quot;, &quot;don\&#39;t&quot;, &quot;want&quot;, &quot;realism.&quot;, &quot;I&quot;, &quot;want&quot;, &quot;magic!&quot;]&quot;</code></pre>

<p><strong>Parameters:</strong>
  <strong>maxSplits:</strong> The maximum number of times to split the collection, or
    one less than the number of subsequences to return. If
    <code>maxSplits + 1</code> subsequences are returned, the last one is a suffix
    of the original collection containing the remaining elements.
    <code>maxSplits</code> must be greater than or equal to zero. The default value
    is <code>Int.max</code>.
  <strong>omittingEmptySubsequences:</strong> If <code>false</code>, an empty subsequence is
    returned in the result for each pair of consecutive elements
    satisfying the <code>isSeparator</code> predicate and for each element at the
    start or end of the collection satisfying the <code>isSeparator</code>
    predicate. The default value is <code>true</code>.
  <strong>isSeparator:</strong> A closure that takes an element as an argument and
    returns a Boolean value indicating whether the collection should be
    split at that element.
<strong>Returns:</strong> An array of subsequences, split from this collection&#39;s
  elements.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func split(maxSplits: Int = default, omittingEmptySubsequences: Bool = default, whereSeparator isSeparator: ((key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; [Slice&lt;Dictionary&lt;Key, Value&gt;&gt;]</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-starts-with_by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-starts-with_by_">func starts(<wbr>with:<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-starts-with_by_"><div class="p">
    <p>Returns a Boolean value indicating whether the initial elements of the
sequence are equivalent to the elements in another sequence, using
the given predicate as the equivalence test.</p>

<p>The predicate must be a <em>equivalence relation</em> over the elements. That
is, for any elements <code>a</code>, <code>b</code>, and <code>c</code>, the following conditions must
hold:</p>

<ul><li><code>areEquivalent(a, a)</code> is always <code>true</code>. (Reflexivity)</li><li><code>areEquivalent(a, b)</code> implies <code>areEquivalent(b, a)</code>. (Symmetry)</li><li>If <code>areEquivalent(a, b)</code> and <code>areEquivalent(b, c)</code> are both <code>true</code>, then
<code>areEquivalent(a, c)</code> is also <code>true</code>. (Transitivity)</li></ul>

<p><strong>Parameters:</strong>
  <strong>possiblePrefix:</strong> A sequence to compare to this sequence.
  <strong>areEquivalent:</strong> A predicate that returns <code>true</code> if its two arguments
    are equivalent; otherwise, <code>false</code>.
<strong>Returns:</strong> <code>true</code> if the initial elements of the sequence are equivalent
  to the elements of <code>possiblePrefix</code>; otherwise, <code>false</code>. If
  <code>possiblePrefix</code> has no elements, the return value is <code>true</code>.</p>

<p><strong>See Also:</strong> <code>starts(with:)</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func starts&lt;PossiblePrefix where PossiblePrefix : Sequence, PossiblePrefix.Iterator.Element == Iterator.Element&gt;(with possiblePrefix: PossiblePrefix, by areEquivalent: ((key: Key, value: Value), (key: Key, value: Value)) throws -&gt; Bool) rethrows -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-suffix_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-suffix_">func suffix(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-suffix_"><div class="p">
    <p>Returns a subsequence, up to the given maximum length, containing the
final elements of the collection.</p>

<p>If the maximum length exceeds the number of elements in the collection,
the result contains all the elements in the collection.</p>

<pre><code class="language-swift">let numbers = [1, 2, 3, 4, 5]
print(numbers.suffix(2))
// Prints &quot;[4, 5]&quot;
print(numbers.suffix(10))
// Prints &quot;[1, 2, 3, 4, 5]&quot;</code></pre>

<p><strong><code>maxLength</code>:</strong>  The maximum number of elements to return. The
  value of <code>maxLength</code> must be greater than or equal to zero.
<strong>Returns:</strong> A subsequence terminating at the end of the collection with at
  most <code>maxLength</code> elements.</p>

<p><strong>Complexity:</strong> O(<em>n</em>), where <em>n</em> is the length of the collection.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func suffix(_ maxLength: Int) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>,    <a href="../../protocol/Sequence/"><code>Sequence</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-suffix-from_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-suffix-from_">func suffix(<wbr>from:)</a>
        
<div class="comment collapse" id="comment-func-suffix-from_"><div class="p">
    <p>Returns a subsequence from the specified position to the end of the
collection.</p>

<p>The following example searches for the index of the number <code>40</code> in an
array of integers, and then prints the suffix of the array starting at
that index:</p>

<pre><code class="language-swift">let numbers = [10, 20, 30, 40, 50, 60]
if let i = numbers.index(of: 40) {
    print(numbers.suffix(from: i))
}
// Prints &quot;[40, 50, 60]&quot;</code></pre>

<p>Passing the collection&#39;s <code>endIndex</code> as the <code>start</code> parameter results in
an empty subsequence.</p>

<pre><code class="language-swift">print(numbers.suffix(from: numbers.endIndex))
// Prints &quot;[]&quot;</code></pre>

<p><strong><code>start</code>:</strong>  The index at which to start the resulting subsequence.
  <code>start</code> must be a valid index of the collection.
<strong>Returns:</strong> A subsequence starting at the <code>start</code> position.</p>

<p><strong>Complexity:</strong> O(1)</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func suffix(from start: DictionaryIndex&lt;Key, Value&gt;) -&gt; Slice&lt;Dictionary&lt;Key, Value&gt;&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Collection/"><code>Collection</code></a>    
</div></div>
</div>
<div class="declaration" id="func-updatevalue_-value-forkey_-key">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-updatevalue_-value-forkey_-key">mutating func updateValue(<wbr>_:<wbr> Value, forKey: Key)</a>
        
<div class="comment collapse" id="comment-func-updatevalue_-value-forkey_-key"><div class="p">
    <p>Updates the value stored in the dictionary for the given key, or adds a
new key-value pair if the key does not exist.</p>

<p>Use this method instead of key-based subscripting when you need to know
whether the new value supplants the value of an existing key. If the
value of an existing key is updated, <code>updateValue(_:forKey:)</code> returns
the original value.</p>

<pre><code class="language-swift">var hues = [&quot;Heliotrope&quot;: 296, &quot;Coral&quot;: 16, &quot;Aquamarine&quot;: 156]

if let oldValue = hues.updateValue(18, forKey: &quot;Coral&quot;) {
    print(&quot;The old value of \(oldValue) was replaced with a new one.&quot;)
}
// Prints &quot;The old value of 16 was replaced with a new one.&quot;</code></pre>

<p>If the given key is not present in the dictionary, this method adds the
key-value pair and returns <code>nil</code>.</p>

<pre><code class="language-swift">if let oldValue = hues.updateValue(330, forKey: &quot;Cerise&quot;) {
    print(&quot;The old value of \(oldValue) was replaced with a new one.&quot;)
} else {
    print(&quot;No value was found in the dictionary for that key.&quot;)
}
// Prints &quot;No value was found in the dictionary for that key.&quot;</code></pre>

<p><strong>Parameters:</strong>
  <strong>value:</strong> The new value to add to the dictionary.
  <strong>key:</strong> The key to associate with <code>value</code>. If <code>key</code> already exists in
    the dictionary, <code>value</code> replaces the existing associated value. If
    <code>key</code> isn&#39;t already a key of the dictionary, the <code>(key, value)</code> pair
    is added.
<strong>Returns:</strong> The value that was replaced, or <code>nil</code> if a new key-value pair
  was added.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func updateValue(_ value: Value, forKey key: Key) -&gt; Value?</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-updatevalue-concretekey_-hashable_-value-forkey_-concretekey">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-updatevalue-concretekey_-hashable_-value-forkey_-concretekey">mutating func <wbr>updateValue&lt;ConcreteKey : Hashable&gt;(<wbr>_:<wbr> Value, forKey: ConcreteKey)</a>
        
<div class="comment collapse" id="comment-func-updatevalue-concretekey_-hashable_-value-forkey_-concretekey"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func updateValue&lt;ConcreteKey : Hashable&gt;(_ value: Value, forKey key: ConcreteKey) -&gt; Value?</code>
    
    
</div></div>
</div>


<h3>Conditionally Inherited Items</h3>

<p class="comment">The initializers, methods, and properties listed below may be available on this type under certain conditions (such as methods that are available on <code>Array</code> when its elements are <code>Equatable</code>) or may not ever be available if that determination is beyond SwiftDoc.org's capabilities. Please <a href="https://github.com/SwiftDocOrg/swiftdoc.org/issues">open an issue on GitHub</a> if you see something out of place!</p>





<h4>Where Indices == DefaultIndices<Self></h4>


<div class="declaration inherited" id="indices-defaultindices-self-var-indices_-defaultindices-self">
<a class="toggle-link" data-toggle="collapse" href="#comment-indices-defaultindices-self-var-indices_-defaultindices-self">var indices: DefaultIndices&lt;Dictionary&lt;Key, Value&gt;&gt;</a><div class="comment collapse" id="comment-indices-defaultindices-self-var-indices_-defaultindices-self"><div class="p">
    <p>The indices that are valid for subscripting the collection, in ascending
order.</p>

<p>A collection&#39;s <code>indices</code> property can hold a strong reference to the
collection itself, causing the collection to be non-uniquely referenced.
If you mutate the collection while iterating over its indices, a strong
reference can cause an unexpected copy of the collection. To avoid the
unexpected copy, use the <code>index(after:)</code> method starting with
<code>startIndex</code> to produce indices instead.</p>

<pre><code class="language-swift">var c = MyFancyCollection([10, 20, 30, 40, 50])
var i = c.startIndex
while i != c.endIndex {
    c[i] /= 5
    i = c.index(after: i)
}
// c == MyFancyCollection([2, 4, 6, 8, 10])</code></pre>

    <h4>Declaration</h4>    
    <code class="language-swift">var indices: DefaultIndices&lt;Dictionary&lt;Key, Value&gt;&gt; { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/Collection/"><code>Collection</code></a>
        </div></div>
</div>





